// 枚举
enum Color {
    Red,
    Green,
    Blue,
    Yellow,
}

// 枚举和匹配模式
fn print_color(color: Color) {
    match color {
        Color::Red => println!("Red"),
        Color::Green => println!("Green"),
        Color::Blue => println!("Blue"),
        Color::Yellow => println!("Yellow"),
    }
}

// 枚举(变体，内嵌类型)
enum Location {
    Name(String),
    Number(i32),
    Unknown,
}

impl Location {
    fn print_location(&self) {
        match self {
            Location::Name(name) => println!("Location name: {}", name),
            Location::Number(number) => println!("Location number: {}", number),
            Location::Unknown => println!("Location unknown"),
        }
    }
}

fn main() {
    // 枚举
    let color = Color::Yellow;
    print_color(color);
    // 枚举值所有权会转移，不能再使用
    // let _color = color;

    // 枚举(内嵌类型)
    let l1 = Location::Name("Wuhan".to_owned());
    l1.print_location();
    // 内嵌的类型可以赋值
    let l2 = l1;
    l2.print_location();
    let l3 = Location::Number(1003);
    l3.print_location();
    let l4 = Location::Unknown;
    l4.print_location();
}
